package com.etoc.test.poi.model;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ChannelSettlement {
	private String channelId;
	private String channelName;
	private Date startTime;
	private Date endTime;
	private BigDecimal refundMoney;
	private BigDecimal rebateMoney;
	private Integer lastMonth;
	private Date createDate;
	private List<ProductInfo> dataList;
	public String getChannelId() {
		return channelId;
	}
	public void setChannelId(String channelId) {
		this.channelId = channelId;
	}
	public String getChannelName() {
		return channelName;
	}
	public void setChannelName(String channelName) {
		this.channelName = channelName;
	}
	public Date getStartTime() {
		return startTime;
	}
	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}
	public Date getEndTime() {
		return endTime;
	}
	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}
	public BigDecimal getRefundMoney() {
		return refundMoney;
	}
	public void setRefundMoney(BigDecimal refundMoney) {
		this.refundMoney = refundMoney;
	}
	public BigDecimal getRebateMoney() {
		return rebateMoney;
	}
	public void setRebateMoney(BigDecimal rebateMoney) {
		this.rebateMoney = rebateMoney;
	}
	public Integer getLastMonth() {
		return lastMonth;
	}
	public void setLastMonth(Integer lastMonth) {
		this.lastMonth = lastMonth;
	}
	public Date getCreateDate() {
		return createDate;
	}
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	public List<ProductInfo> getDataList() {
		return dataList;
	}
	public void setDataList(List<ProductInfo> dataList) {
		this.dataList = dataList;
	}
	
	public Map<String, Object> describe() {
		DateFormat format = new SimpleDateFormat("yyyy年M月d日");
		DateFormat format2 = new SimpleDateFormat("yyyy年MM月dd日");
		Map<String, Object> map = new HashMap<>();
		map.put("channelId", channelId);
		map.put("channelName", channelName);
		map.put("startTime", startTime == null ? "" : format.format(startTime));
		map.put("endTime", endTime == null ? "" : format.format(endTime));
		map.put("refundMoney", refundMoney == null ? BigDecimal.ZERO : refundMoney.setScale(4, BigDecimal.ROUND_HALF_UP));
		map.put("rebateMoney", rebateMoney == null ? BigDecimal.ZERO : rebateMoney.setScale(4, BigDecimal.ROUND_HALF_UP));
		map.put("lastMonth", lastMonth == null ? "" : lastMonth.toString());
		map.put("createDate", createDate == null ? "" : format2.format(createDate));
		if (dataList !=null && !dataList.isEmpty()) {
			BigDecimal totalSalesMoney = BigDecimal.ZERO;
			for (ProductInfo productInfo : dataList) {
				totalSalesMoney = totalSalesMoney.add(productInfo.getSalesMoney());
			}
			BigDecimal settleMoney = totalSalesMoney.subtract(refundMoney == null ? BigDecimal.ZERO : refundMoney)
					.subtract(rebateMoney == null ? BigDecimal.ZERO : rebateMoney);
			map.put("totalSalesMoney", totalSalesMoney.setScale(4, BigDecimal.ROUND_HALF_UP));
			map.put("settleMoney", settleMoney.setScale(4, BigDecimal.ROUND_HALF_UP));
		}
		return map;
	}
}
